package com.minelx.datamicroscope.core.query.literalcondition;

import com.alibaba.fastjson.JSONObject;
import com.minelx.datamicroscope.core.condition.KeyOperandCondition;
import com.minelx.datamicroscope.core.condition.RawCondition;
import com.minelx.datamicroscope.core.query.AliasedKey;
import com.minelx.datamicroscope.core.query.RawConditionFactory;
import io.gitee.minelx.filesystem.TempPath;

import java.util.List;

public interface LiteralCondition {
    RawCondition toRawCondition(TempPath tempDir);

    static LiteralCondition contentAndField(String content, List<AliasedKey> field) {
        return new ContentAndFieldLiteralCondition(content, field);
    }

    static LiteralCondition keyOperand(RawConditionFactory rawConditionFactory, KeyOperandCondition keyOperandCondition) {
        return new KeyOperandLiteralCondition(rawConditionFactory, keyOperandCondition);
    }

    static LiteralCondition fromContentAndField(JSONObject data) {
        LiteralConditionParser literalConditionParser = LiteralConditionParser.contentAndField();
        if (!literalConditionParser.match(data)) {
            throw new IllegalArgumentException("unexpected content and field json data: " + data);
        }
        return literalConditionParser.createLiteralCondition(data);
    }
}
